USE [master]
GO
/****** Object:  Database [AgriculturalSales]    Script Date: 2025/6/29 0:08:25 ******/
CREATE DATABASE [AgriculturalSales]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'AgriculturalSales', FILENAME = N'D:\GiteeCode\Asp.Net Learn\SQLServer\AgriculturalSales.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
 LOG ON 
( NAME = N'AgriculturalSales_log', FILENAME = N'D:\GiteeCode\Asp.Net Learn\SQLServer\AgriculturalSales_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
 WITH CATALOG_COLLATION = DATABASE_DEFAULT, LEDGER = OFF
GO
ALTER DATABASE [AgriculturalSales] SET COMPATIBILITY_LEVEL = 160
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [AgriculturalSales].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [AgriculturalSales] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [AgriculturalSales] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [AgriculturalSales] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [AgriculturalSales] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [AgriculturalSales] SET ARITHABORT OFF 
GO
ALTER DATABASE [AgriculturalSales] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [AgriculturalSales] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [AgriculturalSales] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [AgriculturalSales] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [AgriculturalSales] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [AgriculturalSales] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [AgriculturalSales] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [AgriculturalSales] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [AgriculturalSales] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [AgriculturalSales] SET  DISABLE_BROKER 
GO
ALTER DATABASE [AgriculturalSales] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [AgriculturalSales] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [AgriculturalSales] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [AgriculturalSales] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [AgriculturalSales] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [AgriculturalSales] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [AgriculturalSales] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [AgriculturalSales] SET RECOVERY FULL 
GO
ALTER DATABASE [AgriculturalSales] SET  MULTI_USER 
GO
ALTER DATABASE [AgriculturalSales] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [AgriculturalSales] SET DB_CHAINING OFF 
GO
ALTER DATABASE [AgriculturalSales] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
ALTER DATABASE [AgriculturalSales] SET TARGET_RECOVERY_TIME = 60 SECONDS 
GO
ALTER DATABASE [AgriculturalSales] SET DELAYED_DURABILITY = DISABLED 
GO
ALTER DATABASE [AgriculturalSales] SET ACCELERATED_DATABASE_RECOVERY = OFF  
GO
EXEC sys.sp_db_vardecimal_storage_format N'AgriculturalSales', N'ON'
GO
ALTER DATABASE [AgriculturalSales] SET QUERY_STORE = ON
GO
ALTER DATABASE [AgriculturalSales] SET QUERY_STORE (OPERATION_MODE = READ_WRITE, CLEANUP_POLICY = (STALE_QUERY_THRESHOLD_DAYS = 30), DATA_FLUSH_INTERVAL_SECONDS = 900, INTERVAL_LENGTH_MINUTES = 60, MAX_STORAGE_SIZE_MB = 1000, QUERY_CAPTURE_MODE = AUTO, SIZE_BASED_CLEANUP_MODE = AUTO, MAX_PLANS_PER_QUERY = 200, WAIT_STATS_CAPTURE_MODE = ON)
GO
USE [AgriculturalSales]
GO
/****** Object:  Table [dbo].[Order]    Script Date: 2025/6/29 0:08:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Order](
	[OrderId] [int] IDENTITY(2001,1) NOT NULL,
	[UserId] [int] NOT NULL,
	[OrderNum] [int] NOT NULL,
	[OrderState] [nvarchar](20) NOT NULL,
	[TotalAmout] [decimal](10, 2) NOT NULL,
	[DeliveryAddr] [nvarchar](200) NULL,
	[ContactPhone] [nvarchar](20) NULL,
	[UpdateAt] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[OrderId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[OrderProduct]    Script Date: 2025/6/29 0:08:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[OrderProduct](
	[OrderId] [int] NOT NULL,
	[ProductId] [int] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[OrderId] ASC,
	[ProductId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Payment]    Script Date: 2025/6/29 0:08:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Payment](
	[PayId] [int] IDENTITY(3001,1) NOT NULL,
	[OrderId] [int] NOT NULL,
	[PayMethod] [nvarchar](20) NOT NULL,
	[PayAmout] [decimal](10, 2) NOT NULL,
	[PayState] [nvarchar](20) NOT NULL,
	[PayTime] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[PayId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Product]    Script Date: 2025/6/29 0:08:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Product](
	[ProductId] [int] IDENTITY(1001,1) NOT NULL,
	[CategoryId] [int] NOT NULL,
	[UserId] [int] NOT NULL,
	[Name] [nvarchar](100) NOT NULL,
	[Origin] [nvarchar](100) NULL,
	[Price] [decimal](10, 2) NOT NULL,
	[Inventory] [int] NOT NULL,
	[Unit] [nvarchar](20) NULL,
	[Descr] [nvarchar](500) NULL,
	[ImageUrl] [nvarchar](200) NULL,
PRIMARY KEY CLUSTERED 
(
	[ProductId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[ProductCategory]    Script Date: 2025/6/29 0:08:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ProductCategory](
	[CategoryId] [int] IDENTITY(1,1) NOT NULL,
	[CategoryName] [nvarchar](100) NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[CategoryId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Users]    Script Date: 2025/6/29 0:08:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Users](
	[UserId] [int] IDENTITY(5301,1) NOT NULL,
	[UserName] [nvarchar](50) NOT NULL,
	[Password] [nvarchar](100) NOT NULL,
	[Phone] [nvarchar](20) NULL,
	[UserImagee] [nvarchar](200) NULL,
	[Address] [nvarchar](200) NULL,
	[UserType] [nvarchar](10) NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[Order] ON 

INSERT [dbo].[Order] ([OrderId], [UserId], [OrderNum], [OrderState], [TotalAmout], [DeliveryAddr], [ContactPhone], [UpdateAt]) VALUES (2001, 5302, 3, N'已支付', CAST(42.30 AS Decimal(10, 2)), N'广西桂林市象山区解放路123号', N'13800138002', CAST(N'2025-06-27T15:15:34.070' AS DateTime))
INSERT [dbo].[Order] ([OrderId], [UserId], [OrderNum], [OrderState], [TotalAmout], [DeliveryAddr], [ContactPhone], [UpdateAt]) VALUES (2002, 5303, 2, N'待支付', CAST(63.60 AS Decimal(10, 2)), N'广西柳州市城中区中山路456号', N'13800138003', CAST(N'2025-06-27T15:15:34.070' AS DateTime))
INSERT [dbo].[Order] ([OrderId], [UserId], [OrderNum], [OrderState], [TotalAmout], [DeliveryAddr], [ContactPhone], [UpdateAt]) VALUES (2003, 5304, 4, N'已发货', CAST(89.50 AS Decimal(10, 2)), N'广西玉林市玉州区人民路789号', N'13800138004', CAST(N'2025-06-27T15:15:34.070' AS DateTime))
INSERT [dbo].[Order] ([OrderId], [UserId], [OrderNum], [OrderState], [TotalAmout], [DeliveryAddr], [ContactPhone], [UpdateAt]) VALUES (3002, 5302, 1, N'待支付', CAST(12.00 AS Decimal(10, 2)), N'北部湾大学', N'13669456349', CAST(N'2025-06-28T16:39:01.630' AS DateTime))
SET IDENTITY_INSERT [dbo].[Order] OFF
GO
INSERT [dbo].[OrderProduct] ([OrderId], [ProductId]) VALUES (2001, 1001)
INSERT [dbo].[OrderProduct] ([OrderId], [ProductId]) VALUES (2001, 1003)
INSERT [dbo].[OrderProduct] ([OrderId], [ProductId]) VALUES (2001, 1005)
INSERT [dbo].[OrderProduct] ([OrderId], [ProductId]) VALUES (2002, 1002)
INSERT [dbo].[OrderProduct] ([OrderId], [ProductId]) VALUES (2002, 1004)
INSERT [dbo].[OrderProduct] ([OrderId], [ProductId]) VALUES (2003, 1007)
INSERT [dbo].[OrderProduct] ([OrderId], [ProductId]) VALUES (2003, 1009)
INSERT [dbo].[OrderProduct] ([OrderId], [ProductId]) VALUES (2003, 1011)
INSERT [dbo].[OrderProduct] ([OrderId], [ProductId]) VALUES (2003, 1012)
INSERT [dbo].[OrderProduct] ([OrderId], [ProductId]) VALUES (3002, 1012)
GO
SET IDENTITY_INSERT [dbo].[Payment] ON 

INSERT [dbo].[Payment] ([PayId], [OrderId], [PayMethod], [PayAmout], [PayState], [PayTime]) VALUES (3001, 2001, N'微信支付', CAST(42.30 AS Decimal(10, 2)), N'支付成功', CAST(N'2025-06-27T15:15:34.070' AS DateTime))
INSERT [dbo].[Payment] ([PayId], [OrderId], [PayMethod], [PayAmout], [PayState], [PayTime]) VALUES (3002, 2002, N'支付宝', CAST(63.60 AS Decimal(10, 2)), N'未支付', CAST(N'2025-06-27T15:15:34.070' AS DateTime))
INSERT [dbo].[Payment] ([PayId], [OrderId], [PayMethod], [PayAmout], [PayState], [PayTime]) VALUES (3003, 2003, N'银行卡', CAST(89.50 AS Decimal(10, 2)), N'支付成功', CAST(N'2025-06-27T15:15:34.070' AS DateTime))
INSERT [dbo].[Payment] ([PayId], [OrderId], [PayMethod], [PayAmout], [PayState], [PayTime]) VALUES (4002, 3002, N'微信支付', CAST(12.00 AS Decimal(10, 2)), N'未支付', CAST(N'2025-06-28T16:39:01.650' AS DateTime))
SET IDENTITY_INSERT [dbo].[Payment] OFF
GO
SET IDENTITY_INSERT [dbo].[Product] ON 

INSERT [dbo].[Product] ([ProductId], [CategoryId], [UserId], [Name], [Origin], [Price], [Inventory], [Unit], [Descr], [ImageUrl]) VALUES (1001, 1, 5301, N'广西沙糖桔', N'广西梧州', CAST(8.50 AS Decimal(10, 2)), 500, N'斤', N'广西特产沙糖桔，皮薄肉嫩，甜度高，口感极佳', N'~/Image/shatangju.jpg')
INSERT [dbo].[Product] ([ProductId], [CategoryId], [UserId], [Name], [Origin], [Price], [Inventory], [Unit], [Descr], [ImageUrl]) VALUES (1002, 1, 5301, N'广西荔枝', N'广西钦州', CAST(15.80 AS Decimal(10, 2)), 300, N'斤', N'广西优质荔枝，果肉饱满，香甜可口，营养丰富', N'~/Image/lizhi.jpg')
INSERT [dbo].[Product] ([ProductId], [CategoryId], [UserId], [Name], [Origin], [Price], [Inventory], [Unit], [Descr], [ImageUrl]) VALUES (1003, 2, 5305, N'广西白萝卜', N'广西玉林', CAST(3.20 AS Decimal(10, 2)), 800, N'斤', N'广西本地白萝卜，肉质脆嫩，营养价值高', N'~/Image/bailuobo.jpg')
INSERT [dbo].[Product] ([ProductId], [CategoryId], [UserId], [Name], [Origin], [Price], [Inventory], [Unit], [Descr], [ImageUrl]) VALUES (1004, 2, 5305, N'广西菠菜', N'广西南宁', CAST(4.50 AS Decimal(10, 2)), 200, N'斤', N'新鲜菠菜，叶片翠绿，富含维生素和铁质', N'~/Image/bocai.jpg')
INSERT [dbo].[Product] ([ProductId], [CategoryId], [UserId], [Name], [Origin], [Price], [Inventory], [Unit], [Descr], [ImageUrl]) VALUES (1005, 3, 5301, N'广西香米', N'广西贵港', CAST(6.80 AS Decimal(10, 2)), 1000, N'斤', N'广西优质香米，米粒饱满，香味浓郁，口感软糯', N'~/Image/xiangmi.jpg')
INSERT [dbo].[Product] ([ProductId], [CategoryId], [UserId], [Name], [Origin], [Price], [Inventory], [Unit], [Descr], [ImageUrl]) VALUES (1006, 3, 5301, N'广西茶油', N'广西梧州', CAST(45.00 AS Decimal(10, 2)), 150, N'瓶', N'纯正山茶油，营养丰富，适合炒菜和凉拌', N'~/Image/chayou.jpg')
INSERT [dbo].[Product] ([ProductId], [CategoryId], [UserId], [Name], [Origin], [Price], [Inventory], [Unit], [Descr], [ImageUrl]) VALUES (1007, 4, 5305, N'广西土鸡蛋', N'广西百色', CAST(1.50 AS Decimal(10, 2)), 2000, N'个', N'散养土鸡蛋，蛋黄饱满，营养价值高', N'~/Image/tujidan.jpg')
INSERT [dbo].[Product] ([ProductId], [CategoryId], [UserId], [Name], [Origin], [Price], [Inventory], [Unit], [Descr], [ImageUrl]) VALUES (1008, 4, 5305, N'广西黑猪肉', N'广西河池', CAST(28.00 AS Decimal(10, 2)), 100, N'斤', N'优质黑猪肉，肉质鲜美，无污染绿色食品', N'~/Image/heizhurou.jpg')
INSERT [dbo].[Product] ([ProductId], [CategoryId], [UserId], [Name], [Origin], [Price], [Inventory], [Unit], [Descr], [ImageUrl]) VALUES (1009, 5, 5301, N'广西桂花鱼', N'广西桂林', CAST(35.00 AS Decimal(10, 2)), 80, N'斤', N'桂林漓江桂花鱼，肉质鲜嫩，味道鲜美', N'~/Image/guihuayu.jpg')
INSERT [dbo].[Product] ([ProductId], [CategoryId], [UserId], [Name], [Origin], [Price], [Inventory], [Unit], [Descr], [ImageUrl]) VALUES (1010, 5, 5301, N'广西河虾', N'广西柳州', CAST(25.00 AS Decimal(10, 2)), 120, N'斤', N'新鲜河虾，肉质Q弹，营养丰富', N'~/Image/hexia.jpg')
INSERT [dbo].[Product] ([ProductId], [CategoryId], [UserId], [Name], [Origin], [Price], [Inventory], [Unit], [Descr], [ImageUrl]) VALUES (1011, 6, 5305, N'广西田七', N'广西百色', CAST(180.00 AS Decimal(10, 2)), 50, N'斤', N'正宗田七，药用价值高，活血化瘀功效显著', N'~/Image/tianqi.jpg')
INSERT [dbo].[Product] ([ProductId], [CategoryId], [UserId], [Name], [Origin], [Price], [Inventory], [Unit], [Descr], [ImageUrl]) VALUES (1012, 6, 5305, N'广西罗汉果', N'广西桂林', CAST(12.00 AS Decimal(10, 2)), 299, N'个', N'桂林特产罗汉果，清热润肺，天然甜味剂', N'~/Image/luohanguo.jpg')
SET IDENTITY_INSERT [dbo].[Product] OFF
GO
SET IDENTITY_INSERT [dbo].[ProductCategory] ON 

INSERT [dbo].[ProductCategory] ([CategoryId], [CategoryName]) VALUES (1, N'水果')
INSERT [dbo].[ProductCategory] ([CategoryId], [CategoryName]) VALUES (2, N'蔬菜')
INSERT [dbo].[ProductCategory] ([CategoryId], [CategoryName]) VALUES (3, N'粮油米面')
INSERT [dbo].[ProductCategory] ([CategoryId], [CategoryName]) VALUES (4, N'禽畜肉蛋')
INSERT [dbo].[ProductCategory] ([CategoryId], [CategoryName]) VALUES (5, N'水产')
INSERT [dbo].[ProductCategory] ([CategoryId], [CategoryName]) VALUES (6, N'中药材')
INSERT [dbo].[ProductCategory] ([CategoryId], [CategoryName]) VALUES (7, N'加工产品')
SET IDENTITY_INSERT [dbo].[ProductCategory] OFF
GO
SET IDENTITY_INSERT [dbo].[Users] ON 

INSERT [dbo].[Users] ([UserId], [UserName], [Password], [Phone], [UserImagee], [Address], [UserType]) VALUES (5301, N'admin', N'123456', N'138001380012', N'~/Image/admin1.jpg', N'广西南宁市青秀区', N'管理员')
INSERT [dbo].[Users] ([UserId], [UserName], [Password], [Phone], [UserImagee], [Address], [UserType]) VALUES (5302, N'user1', N'123456', N'13800138002', N'~/Image/user1.jpg', N'广西桂林市象山区12号', N'普通用户')
INSERT [dbo].[Users] ([UserId], [UserName], [Password], [Phone], [UserImagee], [Address], [UserType]) VALUES (5303, N'user2', N'123456', N'13800138003', N'~/Image/user2.jpg', N'广西柳州市城中区', N'普通用户')
INSERT [dbo].[Users] ([UserId], [UserName], [Password], [Phone], [UserImagee], [Address], [UserType]) VALUES (5304, N'user3', N'123456', N'13800138004', N'~/Image/user3.jpg', N'广西玉林市玉州区', N'普通用户')
INSERT [dbo].[Users] ([UserId], [UserName], [Password], [Phone], [UserImagee], [Address], [UserType]) VALUES (5305, N'admin1', N'123456', N'13800138005', N'~/Image/admin2.jpg', N'广西百色市右江区', N'管理员')
INSERT [dbo].[Users] ([UserId], [UserName], [Password], [Phone], [UserImagee], [Address], [UserType]) VALUES (5307, N'user666', N'123456', N'19912345678', N'~/Image/user1.jpg', N'北部湾大学', N'普通用户')
INSERT [dbo].[Users] ([UserId], [UserName], [Password], [Phone], [UserImagee], [Address], [UserType]) VALUES (5308, N'uesrllh', N'123456', N'13669456349', N'~/Image/user1.jpg', N'北部湾大学', N'普通用户')
INSERT [dbo].[Users] ([UserId], [UserName], [Password], [Phone], [UserImagee], [Address], [UserType]) VALUES (5309, N'user567', N'123456', N'13669456348', N'~/Image/user1.jpg', N'北部湾大学', N'普通用户')
SET IDENTITY_INSERT [dbo].[Users] OFF
GO
ALTER TABLE [dbo].[Order] ADD  DEFAULT (getdate()) FOR [UpdateAt]
GO
ALTER TABLE [dbo].[Payment] ADD  DEFAULT (getdate()) FOR [PayTime]
GO
ALTER TABLE [dbo].[Order]  WITH CHECK ADD  CONSTRAINT [FK_Order_User] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([UserId])
GO
ALTER TABLE [dbo].[Order] CHECK CONSTRAINT [FK_Order_User]
GO
ALTER TABLE [dbo].[OrderProduct]  WITH CHECK ADD  CONSTRAINT [FK_OrderProduct_Order] FOREIGN KEY([OrderId])
REFERENCES [dbo].[Order] ([OrderId])
GO
ALTER TABLE [dbo].[OrderProduct] CHECK CONSTRAINT [FK_OrderProduct_Order]
GO
ALTER TABLE [dbo].[OrderProduct]  WITH CHECK ADD  CONSTRAINT [FK_OrderProduct_Product] FOREIGN KEY([ProductId])
REFERENCES [dbo].[Product] ([ProductId])
GO
ALTER TABLE [dbo].[OrderProduct] CHECK CONSTRAINT [FK_OrderProduct_Product]
GO
ALTER TABLE [dbo].[Payment]  WITH CHECK ADD  CONSTRAINT [FK_Payment_Order] FOREIGN KEY([OrderId])
REFERENCES [dbo].[Order] ([OrderId])
GO
ALTER TABLE [dbo].[Payment] CHECK CONSTRAINT [FK_Payment_Order]
GO
ALTER TABLE [dbo].[Product]  WITH CHECK ADD  CONSTRAINT [FK_Product_Category] FOREIGN KEY([CategoryId])
REFERENCES [dbo].[ProductCategory] ([CategoryId])
GO
ALTER TABLE [dbo].[Product] CHECK CONSTRAINT [FK_Product_Category]
GO
ALTER TABLE [dbo].[Product]  WITH CHECK ADD  CONSTRAINT [FK_Product_User] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([UserId])
GO
ALTER TABLE [dbo].[Product] CHECK CONSTRAINT [FK_Product_User]
GO
ALTER TABLE [dbo].[Order]  WITH CHECK ADD CHECK  (([OrderState]='已取消' OR [OrderState]='已完成' OR [OrderState]='已发货' OR [OrderState]='已支付' OR [OrderState]='待支付'))
GO
ALTER TABLE [dbo].[Payment]  WITH CHECK ADD CHECK  (([PayMethod]='货到付款' OR [PayMethod]='银行卡' OR [PayMethod]='支付宝' OR [PayMethod]='微信支付'))
GO
ALTER TABLE [dbo].[Payment]  WITH CHECK ADD CHECK  (([PayState]='已退款' OR [PayState]='支付失败' OR [PayState]='支付成功' OR [PayState]='未支付'))
GO
ALTER TABLE [dbo].[Users]  WITH CHECK ADD CHECK  (([UserType]='普通用户' OR [UserType]='管理员'))
GO
USE [master]
GO
ALTER DATABASE [AgriculturalSales] SET  READ_WRITE 
GO
